package com.good.parents

import com.cloudsp.tr.api.ApiRequest
import com.cloudsp.tr.api.config.ApiConfig
import com.cloudsp.tr.api.impl.ApiRequestImplHttp
import com.rpframework.module.common.bottom.UserCheckInReminderTimer
import com.rpframework.module.common.bottom.aop.UserSignRemindAop
import com.rpframework.module.common.bottom.service.impl.SmsServiceImplTrV2
import com.rpframework.module.common.config.Config
import org.springframework.beans.factory.annotation.Configurable
import org.springframework.beans.factory.annotation.Qualifier
import org.springframework.context.annotation.Bean
import org.springframework.data.redis.core.RedisTemplate
import org.springframework.web.reactive.function.client.WebClient
import java.io.Serializable

/**
 * 天瑞短信配置
 */
@Configurable
open class SmsConfigTrV2 {
    @Bean
    open fun apiConfig() = ApiConfig()

    @Bean
    fun apiRequest(apiConfig: ApiConfig) = ApiRequestImplHttp(WebClient.create(apiConfig.apiHost), apiConfig)

    @Bean
    open fun smsService(redisTemplate: RedisTemplate<Serializable, Serializable>,
                        @Qualifier("config")
                        config: Config,
                        apiRequest: ApiRequest) = SmsServiceImplTrV2(redisTemplate, config, apiRequest)

    @Bean
    open fun userCheckInReminderTimer() = UserCheckInReminderTimer()

    @Bean
    open fun userSignRemindAop(userCheckInReminderTimer: UserCheckInReminderTimer) = UserSignRemindAop(userCheckInReminderTimer)
}